#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int minimumWaitingTime(vector<int> tasks) {
    sort(tasks.begin(),tasks.end());
    int result = 0;
    for(int i=tasks.size() - 1, j = 0; i>=1; i--, j++){
        tasks[j] *= i;
        result += tasks[j];
    }
    return result;
}